﻿<Window x:Class="Test.Window7"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gi="clr-namespace:GreyableImage;assembly=GreyableImage"
        Title="Window7"
        Height="300"
        Width="1024">
  
  <Window.Resources>

    <Style TargetType="{x:Type Image}" x:Key="imgStyle">
      <Setter Property="IsEnabled" Value="{Binding IsChecked, ElementName=enableBtn}"/>
      <Style.Triggers>
        <DataTrigger Binding="{Binding IsChecked, ElementName=sourceBtn1}" Value="True">
          <Setter Property="Source" Value="img1.bmp"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding IsChecked, ElementName=sourceBtn1}" Value="False">
          <Setter Property="Source" Value="img2.bmp"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
    
  </Window.Resources>
  
  <Grid>
    <DockPanel>
      <Grid DockPanel.Dock="Top" Margin="10">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <ToggleButton x:Name="sourceBtn1" Grid.Column="0" IsChecked="True">
          <ToggleButton.Style>
            <Style TargetType="{x:Type ToggleButton}">
              <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                  <Setter Property="Content" Value="Source 1 - from style triggers"/>
                </Trigger>
                <Trigger Property="IsChecked" Value="False">
                  <Setter Property="Content" Value="Source 2 - from style triggers"/>
                </Trigger>
              </Style.Triggers>
            </Style>
          </ToggleButton.Style>
        </ToggleButton>
        <ToggleButton x:Name="sourceBtn2" Grid.Column="1" Click="sourceBtn2_Click">
          <ToggleButton.Style>
            <Style TargetType="{x:Type ToggleButton}">
              <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                  <Setter Property="Content" Value="Source 1 - from code"/>
                </Trigger>
                <Trigger Property="IsChecked" Value="False">
                  <Setter Property="Content" Value="Source 2 - from code"/>
                </Trigger>
              </Style.Triggers>
            </Style>
          </ToggleButton.Style>
        </ToggleButton>
        <ToggleButton x:Name="enableBtn" Grid.Column="2" IsChecked="True">
          <ToggleButton.Style>
            <Style TargetType="{x:Type ToggleButton}">
              <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                  <Setter Property="Content" Value="Enabled"/>
                </Trigger>
                <Trigger Property="IsChecked" Value="False">
                  <Setter Property="Content" Value="Disabled"/>
                </Trigger>
              </Style.Triggers>
            </Style>
          </ToggleButton.Style>
        </ToggleButton>
      </Grid>
      
      <Grid Margin="15">
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
          <RowDefinition Height="22"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Image x:Name="img1" Grid.Column="0" Grid.Row="0" Style="{StaticResource imgStyle}"/>

        <Image x:Name="img2" Grid.Column="1" Grid.Row="0" Style="{StaticResource imgStyle}"
               Source="img0.bmp"/>
        
        <Image x:Name="img3" Grid.Column="2" Grid.Row="0" 
               gi:ImageGreyer.IsGreyable="{Binding IsChecked, ElementName=greaybilityBtn}"
               Style="{StaticResource imgStyle}"/>
        <CheckBox Grid.Column="2" Grid.Row="0" x:Name="greaybilityBtn" VerticalAlignment="Top" HorizontalAlignment="Center" >
          <CheckBox.Style>
            <Style TargetType="{x:Type CheckBox}">
              <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                  <Setter Property="Content" Value="Greyability Attached"/>
                </Trigger>
                <Trigger Property="IsChecked" Value="False">
                  <Setter Property="Content" Value="Greyability Detached"/>
                </Trigger>
              </Style.Triggers>
            </Style>
          </CheckBox.Style>
        </CheckBox>
        
        <gi:GreyableImage x:Name="img4" Grid.Column="3" Grid.Row="0" Style="{StaticResource imgStyle}" Stretch="Uniform"/>

        <TextBlock Text="Image (Source is not set)" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center"/>
        <TextBlock Text="Image (Source set in XAML)" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center"/>
        <TextBlock Text="Image (IsGreyable attached)" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center"/>
        <TextBlock Text="GreyableImage" Grid.Column="3" Grid.Row="1" HorizontalAlignment="Center"/>
      </Grid>
    </DockPanel>
  </Grid>
</Window>
